package com.ai.emall.api.pmloginauth.impl;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import com.ai.emall.bean.gbean.SysOp;
import com.ai.emall.business.interfaces.IPmLoginAuthSV;
import com.ai.emall.utils.constants.SysExceptCodeConstants;
import com.ai.emall.utils.exception.BusinessException;
import com.ai.gcf.api.base.vo.ResponseHeader;
import com.ai.gcf.api.emall.pmloginauth.interfaces.IPmLoginAuthDubboSV;
import com.ai.gcf.api.emall.pmloginauth.param.LoginRequest;
import com.ai.gcf.api.emall.pmloginauth.param.LoginResponse;
import com.ai.gcf.api.emall.pmloginauth.param.ModifyPwdRequest;
import com.ai.gcf.api.emall.pmloginauth.param.ModifyPwdResponse;
/** 
 * 
 * @author zhaowg3
 * @Date 2017年1月6日
 */

public class PmLoginAuthDubboSVImpl implements IPmLoginAuthDubboSV {
	@Autowired
	private IPmLoginAuthSV iPmLoginAuthSV;
	
	@Override
	public LoginResponse login(LoginRequest request) throws Exception {
		if(request==null)
			throw new BusinessException(SysExceptCodeConstants.Special.PARAM_IS_NULL, "请求参数为空");
		if(StringUtils.isBlank(request.getUserName()))
			throw new BusinessException(SysExceptCodeConstants.Special.PARAM_IS_NULL, "用户名参数为空");
		if(StringUtils.isBlank(request.getPassWord()))
			throw new BusinessException(SysExceptCodeConstants.Special.PARAM_IS_NULL, "密码参数为空");
		if(StringUtils.isBlank(request.getToken()))
			throw new BusinessException(SysExceptCodeConstants.Special.PARAM_IS_NULL, "随机数参数为空");
		SysOp op = iPmLoginAuthSV.login(request.getUserName(), request.getPassWord(), request.getToken());
		LoginResponse response = new LoginResponse();
		response.setLoginName(op.getLoginName());
		response.setOpCode(op.getOpCode());
		response.setOpId(op.getOpId());
		response.setOpName(op.getOpName());
		ResponseHeader responseHeader = new ResponseHeader(SysExceptCodeConstants.Special.SUCCESS, "成功");
		response.setResponseHeader(responseHeader);
		return response;
	}

	@Override
	public ModifyPwdResponse modifyPwd(ModifyPwdRequest request) throws Exception {
		if(request==null)
			throw new BusinessException(SysExceptCodeConstants.Special.PARAM_IS_NULL, "请求参数为空");
		if(StringUtils.isBlank(request.getUserName()))
			throw new BusinessException(SysExceptCodeConstants.Special.PARAM_IS_NULL, "用户名参数为空");
		if(StringUtils.isBlank(request.getOldPwd()))
			throw new BusinessException(SysExceptCodeConstants.Special.PARAM_IS_NULL, "旧密码参数为空");
		if(StringUtils.isBlank(request.getNewPwd()))
			throw new BusinessException(SysExceptCodeConstants.Special.PARAM_IS_NULL, "新密码参数为空");
		if(StringUtils.isBlank(request.getToken()))
			throw new BusinessException(SysExceptCodeConstants.Special.PARAM_IS_NULL, "随机数参数为空");
		if(request.getOpId()==null)
			throw new BusinessException(SysExceptCodeConstants.Special.PARAM_IS_NULL, "操作员参数为空");
		iPmLoginAuthSV.modifyPwd(request.getUserName(), request.getOldPwd(), request.getNewPwd(), request.getToken(),request.getOpId());
		ModifyPwdResponse response = new ModifyPwdResponse();
		ResponseHeader responseHeader = new ResponseHeader(SysExceptCodeConstants.Special.SUCCESS, "成功");
		response.setResponseHeader(responseHeader);
		return response;
	}

}
